﻿using ReservationModule.Classes;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ReservationModule
{
    public partial class MasterTest : System.Web.UI.Page
    {
//        decimal roomRate = 0;
//        decimal tax = 0;
//        decimal roomCharges = 0;
//        int numberOfRooms = 0;
//        int nights = 0;
//        decimal total = 0;

//        //DataSet ds = new DataSet();
//        //SqlDataAdapter daRooms = new SqlDataAdapter();
//        //SqlConnection cs = new SqlConnection("Data Source=ocalhost;Initial Catalog=hmsdb;Persist Security Info=True;User ID=sa;Password=imsa");
//        protected void Page_Load(object sender, EventArgs e)
//        {
//            if (!IsPostBack)
//            {
//                //"Select Dates" is selected by default
//                tabDatesNights.CssClass = "Clicked";
//                MainView.ActiveViewIndex = 0;

//                //display current date for checkin date
//                tbxCheckindate.Text = DateTime.Today.ToString("dddd, MMMM dd, yyyy");

//                //display following date for checkout date as minimum and default no. of nights is 1
//                tbxCheckoutdate.Text = DateTime.Today.AddDays(1).ToString("dddd, MMMM dd, yyyy");

//                //auto add all countries' names to drop down list
//                Dictionary<string, string> objDic = new Dictionary<string, string>();
//                foreach (CultureInfo ObjCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
//                {
//                    RegionInfo objRegionInfo = new RegionInfo(ObjCultureInfo.Name);
//                    if (!objDic.ContainsKey(objRegionInfo.EnglishName))
//                    {
//                        objDic.Add(objRegionInfo.EnglishName, objRegionInfo.EnglishName);
//                    }
//                }

//                var obj = objDic.OrderBy(p => p.Key);
//                foreach (KeyValuePair<string, string> val in obj)
//                {
//                    ddlCountry.Items.Add(new ListItem(val.Key, val.Value));
//                }

//                //set minimum credit card expiry month and year to current
//                string currentMonth = DateTime.Today.Month.ToString();
//                int currentYear = DateTime.Today.Year;
//                ddlExpiryMonth.Text = Convert.ToString(currentMonth);
//                ddlExpiryYear.Text = Convert.ToString(currentYear);
//            }

//            //prevent selection of past dates
//            tbxCheckindate_CalendarExtender.StartDate = DateTime.Today;
//            tbxCheckoutdate_CalendarExtender.StartDate = DateTime.Today.AddDays(1);
//            tbxCheckindate_CalendarExtender2.StartDate = DateTime.Today;
//            tbxCheckoutdate_CalendarExtender2.StartDate = DateTime.Today.AddDays(1);

//            //confirmation page
//            lblCheckInDate.Text = tbxCheckindate.Text;
//            lblCheckOutDate.Text = tbxCheckoutdate.Text;
//            lblNights.Text = ddlNights.Text;
//            lblAdults.Text = ddlAdults.Text;
//            lblChildren.Text = ddlChildren.Text;
//            lblRoomType.Text = rblRoomTypes.Text;
//            lblRoomRate.Text = tbxRoomRates.Text;
//            lblNumberOfRooms.Text = rblNumberOfRooms.Text;
//            lblRoomCharges.Text = tbxRoomCharges.Text;
//            lblTax.Text = tbxTax.Text;
//            lblTotal.Text = tbxTotal.Text;
//            lblPaymentType.Text = ddlPaymentTypes.Text;
//            lblCreditCardNumber.Text = tbxCreditCardNumber.Text;
//            lblNameOfCardHolder.Text = tbxNameOfCardHolder.Text;
//            lblExpiryMonth.Text = ddlExpiryMonth.Text;
//            lblExpiryYear.Text = ddlExpiryYear.Text;
//            lblFirstName.Text = tbxFirstName.Text;
//            lblLastName.Text = tbxLastName.Text;
//            lblNRIC.Text = tbxNRIC.Text;
//            lblGender.Text = rblGender.Text;
//            lblDateOfBirth.Text = tbxDOB.Text;
//            lblNationality.Text = tbxNationality.Text;
//            lblAddress1.Text = tbxAddress1.Text;
//            lblAddress2.Text = tbxAddress2.Text;
//            lblAddress3.Text = tbxAddress3.Text;
//            lblCity.Text = tbxCity.Text;
//            lblCountry.Text = ddlCountry.SelectedValue;
//            lblPostalCode.Text = tbxPostalCode.Text;
//            lblContactNumber.Text = tbxContactNumber.Text;
//            lblEmail.Text = tbxEmail.Text;
//            taCfmComments.InnerText = taComments.InnerText;
//        }

//        protected void tabDatesNights_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Clicked";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Initial";
//            MainView.ActiveViewIndex = 0;
//        }

//        protected void tabRoomsRates_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Clicked";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Initial";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 1;
//        }

//        protected void tabPersonalDetails_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Clicked";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Initial";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            tabRoomsRates.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 2;
//        }
//        protected void tabPaymentDetails_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Clicked";
//            tabConfirmation.CssClass = "Initial";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            tabRoomsRates.Enabled = Convert.ToBoolean("True");
//            tabPaymentDetails.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 3;
//        }

//        protected void tabConfirmation_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Clicked";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            tabRoomsRates.Enabled = Convert.ToBoolean("True");
//            tabPersonalDetails.Enabled = Convert.ToBoolean("True");
//            tabPaymentDetails.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 4;
//        }

//        protected void btnContinue1_Click(object sender, EventArgs e)
//        {

//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Clicked";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Initial";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 1;
//        }

//        protected void btnContinue2_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Clicked";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Initial";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            tabRoomsRates.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 2;
//        }

//        protected void btnContinue3_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Clicked";
//            tabConfirmation.CssClass = "Initial";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            tabRoomsRates.Enabled = Convert.ToBoolean("True");
//            tabPersonalDetails.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 3;
//        }

//        protected void btnContinue4_Click(object sender, EventArgs e)
//        {
//            tabDatesNights.CssClass = "Initial";
//            tabRoomsRates.CssClass = "Initial";
//            tabPersonalDetails.CssClass = "Initial";
//            tabPaymentDetails.CssClass = "Initial";
//            tabConfirmation.CssClass = "Clicked";
//            tabDatesNights.Enabled = Convert.ToBoolean("True");
//            tabRoomsRates.Enabled = Convert.ToBoolean("True");
//            tabPersonalDetails.Enabled = Convert.ToBoolean("True");
//            tabPaymentDetails.Enabled = Convert.ToBoolean("True");
//            MainView.ActiveViewIndex = 4;
//        }

//        protected void tbxCheckindate_TextChanged(object sender, EventArgs e)
//        {
//            DateTime checkinDate = Convert.ToDateTime(tbxCheckindate.Text);
//            int nights = Convert.ToInt32(ddlNights.SelectedItem.Value);
//            checkinDate = checkinDate.AddDays(nights);
//            tbxCheckoutdate.Text = checkinDate.ToString("dddd, MMMM dd, yyyy");
//        }

//        protected void tbxCheckoutdate_TextChanged(object sender, EventArgs e)
//        {
//            DateTime checkoutDate = Convert.ToDateTime(tbxCheckoutdate.Text);
//            int nights = Convert.ToInt32(ddlNights.SelectedItem.Value);
//            DateTime checkinDate = checkoutDate.AddDays(-nights);
//            int result = DateTime.Compare(checkinDate, DateTime.Today);
//            if (result > 0)
//                tbxCheckindate.Text = checkinDate.ToString("dddd, MMMM dd, yyyy");
//            else
//            {
//                int difference = Convert.ToInt32((checkoutDate - DateTime.Today).TotalDays);
//                ddlNights.Text = Convert.ToString(difference);
//            }
//        }

//        protected void ddlNights_SelectedIndexChanged(object sender, EventArgs e)
//        {
//            DateTime checkinDate = Convert.ToDateTime(tbxCheckindate.Text);
//            int nights = Convert.ToInt32(ddlNights.SelectedItem.Value);
//            checkinDate = checkinDate.AddDays(nights);
//            tbxCheckoutdate.Text = checkinDate.ToString("dddd, MMMM dd, yyyy");
//        }

//        protected void rblRoomTypes_SelectedIndexChanged(object sender, EventArgs e)
//        {
//            if (rblRoomTypes.Text == "Single")
//            {
//                roomRate = 399.00M;
//                tax = 50.00M;
//                tbxRoomRates.Text = Convert.ToString(roomRate);
//                tbxTax.Text = Convert.ToString(tax);
//            }
//            else if (rblRoomTypes.Text == "Double")
//            {
//                roomRate = 699.00M;
//                tax = 100.00M;
//                tbxRoomRates.Text = Convert.ToString(roomRate);
//                tbxTax.Text = Convert.ToString(tax);
//            }
//            else
//            {
//                roomRate = 999.00M;
//                tax = 150.00M;
//                tbxRoomRates.Text = Convert.ToString(roomRate);
//                tbxTax.Text = Convert.ToString(tax);
//            }


//            numberOfRooms = Convert.ToInt32(rblNumberOfRooms.Text);
//            nights = Convert.ToInt32(ddlNights.Text);
//            roomCharges = roomRate * numberOfRooms * nights;
//            tbxRoomCharges.Text = Convert.ToString(roomCharges);
//            total = roomCharges + tax;
//            tbxTotal.Text = Convert.ToString(total);
//        }

//        protected void rblNumberOfRooms_SelectedIndexChanged(object sender, EventArgs e)
//        {
//            if (rblRoomTypes.Text == "Single")
//            {
//                roomRate = 399.00M;
//                tax = 50.00M;
//                tbxRoomRates.Text = Convert.ToString(roomRate);
//                tbxTax.Text = Convert.ToString(tax);
//            }
//            else if (rblRoomTypes.Text == "Double")
//            {
//                roomRate = 699.00M;
//                tax = 100.00M;
//                tbxRoomRates.Text = Convert.ToString(roomRate);
//                tbxTax.Text = Convert.ToString(tax);
//            }
//            else
//            {
//                roomRate = 999.00M;
//                tax = 150.00M;
//                tbxRoomRates.Text = Convert.ToString(roomRate);
//                tbxTax.Text = Convert.ToString(tax);
//            }

//            numberOfRooms = Convert.ToInt32(rblNumberOfRooms.Text);
//            nights = Convert.ToInt32(ddlNights.Text);
//            roomCharges = roomRate * numberOfRooms * nights;
//            tbxRoomCharges.Text = Convert.ToString(roomCharges);
//            total = roomCharges + tax;
//            tbxTotal.Text = Convert.ToString(total);
//        }

//        protected void btnConfirmBooking_Click(object sender, EventArgs e)
//        {


//            string paymentType = lblPaymentType.Text;
//            string creditCardNumber = lblCreditCardNumber.Text;
//            string nameOfCardHolder = lblNameOfCardHolder.Text;
//            string expiryMonth = lblExpiryMonth.Text;
//            int expiryYear = Convert.ToInt32(lblExpiryYear.Text);
//            string expiryDate = expiryMonth + expiryYear;
//            CreditCard cc = new CreditCard() { CreditCardNumber1 = creditCardNumber, ExpiryDate1 = expiryDate, NameOfCardHolder1 = nameOfCardHolder, CreditCardType1 = paymentType };
//            int creditCardRows = DBManager.CreateCreditCard(cc);

//            string nric = lblNRIC.Text;
//            string firstName = lblFirstName.Text;
//            string lastName = lblLastName.Text;
//            string postalCode = lblPostalCode.Text;
//            string city = lblCity.Text;
//            string country = ddlCountry.Text;
//            string nationality = tbxNationality.Text;
//            string contactNumber = lblContactNumber.Text;
//            string address = lblAddress1.Text + " " + lblAddress2.Text + " " + lblAddress3.Text;
//            string email = lblEmail.Text;
//            string gender = lblGender.Text;
//            DateTime dob = Convert.ToDateTime(tbxDOB.Text);
//            string additionalComment = taCfmComments.InnerText;

//            Customer cu = new Customer() { NRIC1 = nric, FirstName1 = firstName, LastName1 = lastName, PostalCode1 = postalCode, City1 = city, Country1 = country, Nationality1 = nationality, ContactNumber1 = contactNumber, Address1 = address, Email1 = email, Gender1 = gender, DateOfBirth1 = dob, AdditionalComment1 = additionalComment };
//            int customerRows = DBManager.CreateCustomer(cu);


//            int customerID = 0;
//            Customer cu2 = DBManager.GetCustomerByNRIC(nric);
//            if (cu2 != null)
//                customerID = cu2.CustomerID1;

//            DateTime checkInDate = Convert.ToDateTime(lblCheckInDate.Text);
//            DateTime checkOutDate = Convert.ToDateTime(lblCheckOutDate.Text);
//            int numberOfGuestAdults = Convert.ToInt32(lblAdults.Text);
//            int numberOfGuestChildren = Convert.ToInt32(lblChildren.Text);
//            int numberOfNights = Convert.ToInt32(lblNights.Text);
//            string reservationStatus = "Awaiting Check In";
//            string additionalremarks = taCfmComments.InnerText;
//            int numberOfRoom = Convert.ToInt32(lblNumberOfRooms.Text);
//            Reservation re = new Reservation() { CustomerID1 = customerID, DesiredCheckInDate1 = checkInDate, DesiredCheckOutDate1 = checkOutDate, NumberOfGuestAdults1 = numberOfGuestAdults, NumberOfGuestChildren1 = numberOfGuestChildren, NumberOfNights1 = numberOfNights, ReservationStatus1 = reservationStatus, AdditionalRemarks1 = additionalremarks, NumberOfRooms1 = numberOfRoom };
//            int reservationRows = DBManager.CreateReservation(re);

//            int reservationID = 0;
//            Reservation re2 = DBManager.GetReservationByCustomerID(customerID);
//            if (re2 != null)
//                reservationID = re2.ReservationID1;

//            string roomtype = rblRoomTypes.Text;
//            int numberofrooms = Convert.ToInt32(rblNumberOfRooms.Text);
//            Reservation re3 = new Reservation() { NumberOfRooms1 = numberofrooms, ReservationID1 = reservationID };
//            Room r = new Room() { RoomStatus1 = "Rerserved", RoomType1 = roomtype, ReservationID1 = reservationID };
//            int row = DBManager.UpdateRoom(r, re3);

//        }
    }
}





